﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace RegexLib.Web
{
	public class GlobalApplication : System.Web.HttpApplication
	{
		public static void RegisterRoutes(RouteCollection routes)
		{
			// Note: Change the URL to "{controller}.mvc/{action}/{id}" to enable
			//       automatic support on IIS6 and IIS7 classic mode

			routes.Add(new Route("ViewRegex/{accessKey}", new MvcRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { controller = "Regex", action = "ViewRegex", accessKey = "" }),
			});

			routes.Add(new Route("Keyword/{text}/{pageIndex}/{pageSize}", new MvcRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { controller = "Keywords", action = "ViewKeyword", text = "", pageIndex = 1, pageSize = 20 }),
			});

			routes.Add(new Route("UserContributions/{pageIndex}/{pageSize}", new MvcRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { controller = "User", action = "Contributions", pageIndex = 1, pageSize = 50 }),
			});

			routes.Add(new Route("User/{accessKey}/{pageIndex}/{pageSize}", new MvcRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { controller = "User", action = "Index", pageIndex = 1, pageSize = 30 }),
			});

			routes.Add(new Route("Regex/All/{pageIndex}/{pageSize}", new MvcRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { controller = "Regex", action = "All", pageIndex = 1, pageSize = 50 }),
			});

			routes.Add(new Route("Admin/{controller}/{action}", new MvcRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { controller = "AdminHome", action = "Index" }),
			});

			routes.Add(new Route("{controller}/{action}/{id}", new MvcRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { action = "Index", id = "" }),
			});

			routes.Add(new Route("Default.aspx", new MvcRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id="" }),
			});
		}

		protected void Application_Start(object sender, EventArgs e)
		{
			RegisterRoutes(RouteTable.Routes);
		}
	}
}